﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Forum.Domain.Managers;
using Forum.ExternalInterface.Entities;
using Forum.ExternalInterface.Interfaces;

namespace Forum.Web.Services
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ForumService //: IForumService
    {
        [OperationContract]
        public void DoWork()
        {
            // Add your operation implementation here
            return;
        }

        [OperationContract]
        public List<Post> GetPosts()
        {
            return ConvertPosts(new PostManager().GetAllPosts());
        }

        private List<Post> ConvertPosts(List<Forum.DataAccess.DbModel.Post> intPosts)
        {
            List<Post> result = new List<Post>();

            foreach (DataAccess.DbModel.Post intPost in intPosts)
            {
                result.Add(new Post
                               {
                                   Id = intPost.Id,
                                   CreateOn = intPost.CreatedOn
                               });
            }
            return result;
        } 

        // Add more operations here and mark them with [OperationContract]
    }
}
